package com.songxh.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.songxh.pojo.Student;
import com.songxh.pojo.Teacher;
import com.songxh.service.StudentService;
import com.songxh.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author songxh
 * @create 2022-04-18-19:36
 */
@Api("Student控制器")
@RestController
@RequestMapping("/sms/studentController")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @ApiOperation("获取学生信息")
    @GetMapping("/getStudentByOpr/{pageNo}/{pageSize}")
    public Result getStudentByOpr(
            @ApiParam("页码")
            @PathVariable("pageNo")Integer pageNo,
            @ApiParam("每一页的页数")
            @PathVariable("pageSize")Integer pageSize,
            String clazzName,
            String name
    ){
        Page<Student> page=new Page<>(pageNo,pageSize);
        IPage<Student> pageRes =studentService.getTeacherByOpr(page,name,clazzName);
        return Result.ok(pageRes);
    }

    @ApiOperation("删除学生信息")
    @DeleteMapping("/delStudentById")
    public Result delStudentById(@ApiParam("需要删除的Student的id值的JSON集合")@RequestBody List<Integer> ids){
        // .removeByIds(ids)该方法来自IService，由mybatisplus提供
        studentService.removeByIds(ids);
        return Result.ok();
    }


    @ApiOperation("添加或者修改学生信息")
    @PostMapping("/addOrUpdateStudent")
    public Result addOrUpdateStudent(@ApiParam("该Student信息的JSON内容")@RequestBody Student student){
        //实现服务层的增加与修改操作
        //该方法在IService中已经存在，故而直接用即可
        studentService.saveOrUpdate(student);
        return Result.ok();
    }


}
